﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;
using Utility;

namespace DAL
{
    public class MessageDAO
    {

        public static int InsertMessage(Entity.Message msg)
        {
            string sql = SqlSentence.insertMessage;
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId", msg.UserId), 
                new SqlParameter("@MessageContent", msg.MessageContent)              
            };
            return SqlHelper.ExecteNonQueryText(sql, parameters);
        }

        public static DataTable GetUnreadMessages(int uid)
        {
            string sql = SqlSentence.getUnreadMessages;
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId", uid)          
            };
            return SqlHelper.GetSingleTableText(sql, parameters);
        }

        public static DataTable GetReadMessages(int uid)
        {
            string sql = SqlSentence.getReadMessages;
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId", uid)          
            };
            return SqlHelper.GetSingleTableText(sql, parameters);
        }

        public static object UpdateMessageReadStatus(Message message)
        {
            string sql = SqlSentence.updateMessageReadStatus;
            SqlParameter[] parameters =
            {
                new SqlParameter("@MessageId", message.MessageId),          
                new SqlParameter("@IsRead", message.IsRead)          
            };
            return SqlHelper.ExecteNonQueryText(sql, parameters);
        }
    }
}
